package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuItemDetailFeignClient;
import com.atguigu.gmall.item.to.SkuDetailTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

//跳转到静态页面
@Controller
public class itemController {

    @Autowired
    SkuItemDetailFeignClient skuItemDetailFeignClient;

//    展示详情的SKU页面，就是商品页面

    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId,
                       Model model){


        Result<SkuDetailTO> skuDetail = skuItemDetailFeignClient.getSkuDetail(skuId);

//        对着static页面进行封装
        SkuDetailTO skuDetailTO = skuDetail.getData();

//        取到数据
        if (skuDetailTO != null) {
            model.addAttribute("categoryView",skuDetailTO.getCategoryView());
            model.addAttribute("skuInfo",skuDetailTO.getSkuInfo());
            model.addAttribute("price",skuDetailTO.getPrice());
            model.addAttribute("spuSaleAttrList",skuDetailTO.getSpuSaleAttrList());
            model.addAttribute("valuesSkuJson",skuDetailTO.getValuesSkuJson());

            return "item/index";
        }

//      数据库中没有数据
        return "item/404";
    }
}
